(function(c) {
	c.fn.pager = function(d) {
		var e = c.extend( {}, c.fn.pager.defaults, d);
		return this.each(function() {
			c(this).empty().append(
					b(parseInt(d.pagenumber), parseInt(d.pagecount),
							d.buttonClickCallback));
			c(".pages ul a").mouseover(function() {
				document.body.style.cursor = "pointer"
			}).mouseout(function() {
				document.body.style.cursor = "auto"
			})
		})
	};
	function b(e, j, g) {
		var k = c('<ul class="pages"></ul>'); 
		k.append(a("首页", e, j, g)).append(a("前一页", e, j, g));
		var h = 1;
		var f = 9;
		if (e > 4) {
			h = e - 4;
			f = e + 4
		}
		if (f > j) {
			h = j - 8;
			f = j
		}
		if (h < 1) {
			h = 1
		}
		for ( var i = h; i <= f; i++) {
			var d = c('<a style="padding:0 8px 0 7px ;margin-right:5px;">' + (i) + '</a>');
			i == e ? d.css("background","#F60") : d.click(function() {
				g(this.firstChild.data)
			});
			d.appendTo(k)
		}
		k.append(a("下一页", e, j, g)).append(a("尾页", e, j, g));
		return k
	}
	function a(h, d, g, f) {
		var e = c('<a style="padding:0 8px 0 7px ;margin-right:5px;">' + h + "</a>");
		var i = 1;
		switch (h) {
		case "首页":
			i = 1;
			break;
		case "前一页":
			i = d - 1;
			break;
		case "下一页":
			i = d + 1;
			break;
		case "尾页":
			i = g;
			break
		}
		if (h == "首页" || h == "前一页") {
			d <= 1 ? e.addClass("next") : e.click(function() {
				f(i)
			})
		} else if (h == "下一页" || h == "尾页"){
			d >= g ? e.addClass("next") : e.click(function() {
				f(i)
			})
		}
		return e
	}
	c.fn.pager.defaults = {
		pagenumber : 1,
		pagecount : 1
	}
})(jQuery);





$(function(){

/*
	usage:
	$("table.xx").pagination({
		pager : 'div',
		currentPage : 1 ,
		totalPage : 63
	});
 */
$.fn.pagination = function(setting){
		
	setting = $.extend({ 
	}, setting || {}); 
	
	return $(this).each(function(){
					 
		var pid = setting['pager'];
		
		var pcb = function( pageNum ){ 
			var url = window.location.href.toString();
			url = url.replace(/pageCurrentPage=[^&]*/g,'');
			var lastChr = url.charAt( url.length - 1);
			pageNum = ''+pageNum;
			pageNum = pageNum.trim();
			if( url.indexOf('?') > 0 ){
				if( lastChr == '?' || lastChr == '&'  ) {
					url = url + 'pageCurrentPage=' + pageNum;					
				} else {
					url = url + '&pageCurrentPage=' + pageNum;
				}
			} else {
				url = url + '?pageCurrentPage=' + pageNum;
			}
			window.location = url;
		}
 
		$( pid ).pager({  pagenumber:setting.currentPage , pagecount:setting.totalPage , buttonClickCallback:pcb  });
		//if ( setting['recordCount'] && $(".pagination_record").length == 0 ) {
			//$("<span>共" + setting['recordCount'] + "条</span>").insertAfter( $( pid ) );	
		//}
	
	});
	
}

});